package com.xiaotu.zhouyi.controller;


import com.xiaotu.core.asyncs.AsyncsXiaotu;
import com.xiaotu.result.R;
import com.xiaotu.zhouyi.pojo.entity.GuaEight;
import com.xiaotu.zhouyi.pojo.entity.TGuaEight;
import com.xiaotu.zhouyi.service.GuaEightService;
import com.xiaotu.zhouyi.service.TGuaEightService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaotu
 * @since 2022-01-10
 */
@CrossOrigin
@Api("周易八卦")
@RestController
@RequestMapping("/server/zhouyi/guaEight")
public class GuaEightController {
    @Autowired
    private GuaEightService guaEightService;
    @Autowired
    private TGuaEightService tGuaEightService;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private AsyncsXiaotu asyncsXiaotu;
    @GetMapping
    public R getList(){
        List<TGuaEight> list = (List<TGuaEight>)redisTemplate.opsForValue().get("bagua");
        if (list == null){
            list = tGuaEightService.list();
            //异步存储
            asyncsXiaotu.redisMethod(list,"bagua",60*60L);
        }
        return R.ok().data("list",list);
    }
    @GetMapping("/{id}")
    public R getById(@ApiParam(value = "id数据",required = true ,example = "1")@PathVariable Integer id){
        GuaEight byId = guaEightService.getById(id);
        return  R.ok().data("record", byId);
    }
}
